package com.zsrt.java.day20170102.lh.petshop;

public class PetShop {
	/**
	 * 宠物个数
	 */
	private int index;
	/**
	 * 笼子
	 */
	private IPet[] pets; 
	
	//构造方法开辟宠物数组
	public PetShop(int len){
		pets=new IPet[len];
	}
	/**
	 * 添加宠物
	 * @param pet 宠物对象
	 * @return 是否添加成功
	 */
	public boolean add(IPet pet){
		boolean temp=false;
		if(index>=pets.length){
			System.out.println("笼子已满，添加失败");
			return temp;
		}else{
			pets[index]=pet;
			index++;
			System.out.println("添加成功");
			temp=true;
		}
		return temp;
	}
	
	public IPet[] search(String petName){
		int len=0;
		for(int i=0;i<pets.length;i++){
			if(pets[i].getName().contains(petName) || pets[i].getColor().contains(petName)){
				len++;
			}
		}
		//新笼子
		IPet newPets[]=new IPet[len];
		
		for(int i=0;i<pets.length;i++){
			if(pets[i].getName().contains(petName) || pets[i].getColor().contains(petName)){
				newPets[i]=pets[i];
			}
		}
		return newPets;
	}




}
